package com.ellricky.baselib.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import androidx.appcompat.widget.AppCompatEditText;

import com.andr.common.ui.dialog.BaseDialog;
import com.andr.common.util.EmptyUtil;
import com.andr.common.util.ToastUtil;
import com.ellricky.baselib.R;
import com.ellricky.baselib.listener.OnClassHourConfirmListener;
import com.flyco.roundview.RoundTextView;

import java.util.Objects;

public class ClassHourDialog extends BaseDialog {

    private AppCompatEditText etHour;
    private RoundTextView tvConfirm;

    public void setListener(OnClassHourConfirmListener listener) {
        this.listener = listener;
    }

    private OnClassHourConfirmListener listener;

    @Override
    public int getCustomLayoutId() {
        return R.layout.dialog_class_hour;
    }

    public ClassHourDialog(Context context) {
        super(context);
        setGravity(Gravity.CENTER);
    }


    @Override
    public void initWidgets() {

        etHour = findViewById(R.id.etHour);
        tvConfirm = findViewById(R.id.btnSubmit);
        tvConfirm.setOnClickListener(this);
    }


    @Override
    public void onClickView(View v) {

        if (listener == null) return;

        String hour = Objects.requireNonNull(etHour.getText()).toString().trim();
        if (EmptyUtil.isEmpty(hour)){
            ToastUtil.show(context,"请输入课时数");
            return;
        }
        listener.onConfirm(this,hour);

    }

}
